package com.huawei.hwid.update.d;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.KeyEvent;
import com.huawei.hwid.core.d.b;
import com.huawei.hwid.core.d.b.e;

public class f extends a {
    public void a(Activity activity) {
        super.a(activity);
        if (this.c != null) {
            this.f = 5;
            if (this.c.e() && !TextUtils.isEmpty(this.h)) {
                a(g.class);
            } else if (!g() && !a(false)) {
                a(8, this.f);
            }
        }
    }

    public void a() {
        super.a();
    }

    public int f() {
        return 2005;
    }

    public boolean a(int i, int i2, Intent intent) {
        if (this.e && this.b != null) {
            return this.b.a(i, i2, intent);
        }
        if (this.f != 5 || i != f()) {
            return false;
        }
        if (a(this.g, this.i)) {
            a(0, this.f);
        } else {
            a(8, this.f);
        }
        return true;
    }

    public void b() {
        super.b();
    }

    public void a(b bVar) {
        e.b("HiappWizard", "Enter onCancel.", true);
        if (bVar instanceof g) {
            c();
        }
    }

    public void b(b bVar) {
        e.b("HiappWizard", "Enter onDoWork.", true);
        if (bVar instanceof g) {
            bVar.c();
            if (!g() && !a(false)) {
                a(8, this.f);
            }
        }
    }

    private boolean g() {
        Context d = d();
        if (d == null || d.isFinishing() || TextUtils.isEmpty(this.g)) {
            return false;
        }
        try {
            if (b.a(d, "com.huawei.appmarket.intent.action.AppDetail", "com.huawei.appmarket")) {
                Intent intent = new Intent();
                intent.setAction("com.huawei.appmarket.intent.action.AppDetail");
                intent.putExtra("APP_PACKAGENAME", this.g);
                intent.setPackage("com.huawei.appmarket");
                d.startActivityForResult(intent, f());
                return true;
            }
            e.b("HiappWizard", "action is not exist", true);
            return false;
        } catch (ActivityNotFoundException e) {
            e.d("HiappWizard", "can not open hiapp", true);
            return false;
        } catch (Exception e2) {
            e.d("HiappWizard", "Exception", true);
            return false;
        }
    }

    void a(Class<? extends b> cls) {
        e();
        try {
            b bVar = (b) cls.newInstance();
            if (!TextUtils.isEmpty(this.h) && (bVar instanceof g)) {
                ((g) bVar).a(this.h);
            }
            bVar.a((a) this);
            this.d = bVar;
        } catch (InstantiationException e) {
            e.d("HiappWizard", "In showDialog, InstantiationException", true);
        } catch (IllegalAccessException e2) {
            e.d("HiappWizard", "In showDialog, IllegalAccessException", true);
        } catch (IllegalStateException e3) {
            e.d("HiappWizard", "In showDialog, IllegalStateException", true);
        }
    }

    void c() {
        a(13, this.f);
    }

    public void a(int i, KeyEvent keyEvent) {
        if (this.e && this.b != null) {
            this.b.a(i, keyEvent);
        } else if (4 == i) {
            e.b("HiappWizard", "HiappWizard In onKeyUp, Call finish.", true);
            Activity d = d();
            if (d != null && !d.isFinishing()) {
                d.setResult(0, null);
                d.finish();
            }
        }
    }
}
